import { Component, OnInit, Input } from '@angular/core';

@Component({
  selector: 'app-stars',
  templateUrl: './stars.component.html',
  styleUrls: ['./stars.component.css']
})
export class StarsComponent implements OnInit {
  
  @Input() //加上一个input装饰器，表示rating属性是由父组件传递过来的
  private rating: number = 0;

  private stars: boolean[];

  constructor() { }

  ngOnInit() { // 初始化变量
      this.stars = [];
      for (let i = 1; i <= 5; i++) {
        this.stars.push(i > this.rating);   //当i大于rating时返回true,否则返回false
      }
      // this.stars = [false, false, true, true, true]; 
  }  

}
